//
//  UIView+AddLine.m
//  MFWAnnualMeeting
//
//  Created by 陈曦 on 13-12-19.
//  Copyright (c) 2013年 mafengwo. All rights reserved.
//

#import "UIView+AddLine.h"

static NSInteger topTag = 204158131;
static NSInteger bottomTag = 204158132;
static NSInteger leftTag = 204158133;
static NSInteger rightTag = 204158134;

@implementation UIView(AddLine)

- (UIView *)addTopLine
{
    return [self addTopLine:0];
}

- (UIView *)addTopLine:(CGFloat)wm
{
    UIView *line = [self viewWithTag:topTag];
    if (line == nil) {
        UIImageView *image = [[UIImageView alloc] init];
        image.tag = topTag;
        [self addSubview:image];
        line = image;
    }
    line.frame = CGRectMake(wm, 0, self.bounds.size.width-wm*2, 0.5);
    line.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [self bringSubviewToFront:line];
    return line;
}

- (UIView *)getTopLine
{
    UIView *line = [self viewWithTag:topTag];
    return line;
}

- (UIView *)addBottomLine
{
    return [self addBottomLine:0];
}

- (UIView *)addBottomLine:(CGFloat)wm
{
    UIView *line = [self viewWithTag:bottomTag];
    if (line == nil) {
        UIImageView *image = [[UIImageView alloc] init];
        image.tag = bottomTag;
        [self addSubview:image];
        line = image;
    }
    line.frame = CGRectMake(wm, self.bounds.size.height - 0.5, self.bounds.size.width-wm*2, 0.5);
    line.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    [self bringSubviewToFront:line];
    return line;
}

- (UIView *)getBottomLine
{
    UIView *line = [self viewWithTag:bottomTag];
    return line;
}

- (UIView *)addLeftLine
{
    UIView *line = [self viewWithTag:leftTag];
    if (line == nil) {
        UIImageView *image = [[UIImageView alloc] init];
        image.tag = leftTag;
        [self addSubview:image];
        line = image;
    }
    line.frame = CGRectMake(0, 0, 0.5, self.bounds.size.height);
    line.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    [self bringSubviewToFront:line];
    return line;
}

- (UIView *)addRightLine
{
    UIView *line = [self viewWithTag:rightTag];
    if (line == nil) {
        UIImageView *image = [[UIImageView alloc] init];
        image.tag = rightTag;
        [self addSubview:image];
        line = image;
    }
    line.frame = CGRectMake(self.bounds.size.width - 0.5, 0, 0.5, self.bounds.size.height);
    line.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin;
    [self bringSubviewToFront:line];
    return line;
}

@end
